using System;
using System.Linq;
using System.Collections.Generic;

using DemoApp.DataAccess;

using EntModApp.EntServices.Business;
using EntModApp.EntServices.Data;

namespace DemoApp.BusinessLayer 
{
  public partial class SubjectObjectRepository : 
    ISubjectObjectRepository 
  {
    public IBusinessObjectCollection<ISubject> RetrieveAll()
    {
      var query = new SubjectLoadSettings();
      return Retrieve(query);
    }

    public IBusinessObjectCollection<ISubject> Retrieve(SubjectLoadSettings query)
    {
      query = SubjectLoadSettings.FromSubjectLoadSettings(query);
      if (query.AsReadonly)
      {
        var result = CslaSubjectInfoCollection.GetSubjectInfoCollection(query);
        return result;
      }
      else
      {
        var result = CslaSubjectEditCollection.GetSubjectEditCollection(query);
        return result;
      }
    }

    public ISubject RetrieveOne(SubjectLoadSettings query)
    {
      query = SubjectLoadSettings.FromSubjectLoadSettings(query);
      if (query.AsReadonly)
      {
        var result = CslaSubjectInfoCollection.GetSubjectInfoCollection(query);
        return result.FirstOrDefault<ISubject>();
      }
      else
      {
        var result = CslaSubjectEditCollection.GetSubjectEditCollection(query);
        return result.FirstOrDefault<ISubject>();
      }
    }

    public int Count()
    {
      return Count(null);
    }

    public int Count(SubjectLoadSettings query)
    {
      query = SubjectLoadSettings.FromSubjectLoadSettings(query);
      return CslaSubjectInfoCollection.GetCount(query);
    }

    public ISubject New()
    {
      return CslaSubjectEdit.New();
    }

    public void Save(IBusinessObjectCollection<ISubject> collection)
    {
      throw new NotImplementedException();
    }

    public void Save(ISubject obj)
    {
      throw new NotImplementedException();
    }
  }
}
